package com.gxa.k12.course.controller;


import com.gxa.k12.common.util.PageUtils;
import com.gxa.k12.common.util.R;
import com.gxa.k12.course.entity.ChapterEntity;
import com.gxa.k12.course.service.ChapterService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 课程大纲
 *
 * @author wenjie
 * @email wenj73487@gmail.com
 * @date 2021-07-20 11:28:11
 */
@RestController
@Api
@RequestMapping("course/chapter")
public class ChapterController {
    @Autowired
    private ChapterService chapterService;

    /**
     * 列表
     */

    //@RequiresPermissions("course:chapter:list")
//    public R list(@RequestParam Map<String, Object> params) {
//        PageUtils page = chapterService.queryPage(params);
//        return R.ok().put("page", page);
//    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("course:chapter:info")
    public R info(@PathVariable("id") String id) {
            ChapterEntity chapter = chapterService.getById(id);
        return R.ok().put("chapter", chapter);
    }

    /**
     * 保存
     */

    @RequestMapping("/save")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "chapter",paramType = "body",dataType = "Chapter")
    })
    @ApiOperation(value = "这个是课程章节的保存的接口",notes = "这个是课程章节的保存的接口",httpMethod = "POST")
    //@RequiresPermissions("course:chapter:save")
    public R save(@RequestBody ChapterEntity chapter) {
            chapterService.save(chapter);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "chapter",paramType = "body",dataType = "Chapter")
    })
    @ApiOperation(value = "这个是课程章节的修改的接口",notes = "这个是课程章节的修改的接口",httpMethod = "POST")
    //@RequiresPermissions("course:chapter:update")
    public R update(@RequestBody ChapterEntity chapter) {
            chapterService.updateById(chapter);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "chapter",paramType = "query",dataType = "string")
    })
    @ApiOperation(value = "这个是课程章节的删除的接口，传入要修改的id的数组",notes = "这个是课程章节的修改的接口",httpMethod = "POST")
    //@RequiresPermissions("course:chapter:delete")
    public R delete(@RequestBody String[] ids) {
            chapterService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
}
